import { OneModal } from '@/components/one-ui';
import { IOneModalRef } from '@/pages/type';
import { fieldFlowExport, onCloseModalCommon } from '@/utils';
import { Ref, useRef } from 'react';
import { ExportAssetsServices } from '../services';
import moment from 'moment';

const ExportModal = ({ onClose, reqParams }) => {
  /**
   * 弹框的ref
   * */
  const modalRef: Ref<IOneModalRef> = useRef(null);

  /**
   * 导出专家接口
   * */
  const { ExportAssetsRun, ExportAssetsLoading } = ExportAssetsServices();

  /**
   * 弹窗关闭方法
   * */
  const onCloseModal = () => {
    onClose();
  };

  /**
   * 弹窗确认方法
   * */
  const onOkModal = async () => {
    let reqBody: Record<string, any> = { ...reqParams };
    const fileObj = await ExportAssetsRun({ ...reqBody });
    if (!fileObj?.status) {
      fieldFlowExport(fileObj, `物资信息${moment()?.format('YYYYMMDDHHmmss')}.xlsx`);
      onCloseModalCommon(modalRef);
    }
  };

  return (
    <OneModal
      open={true}
      getContainer={false}
      ref={modalRef}
      title={'导出物资'}
      onCancel={onCloseModal}
      onOk={onOkModal}
      width={document.body.clientWidth * 0.23}
      bodyStyle={{ padding: '20px 40px' }}
      confirmLoading={ExportAssetsLoading}
    >
      <div style={{ textAlign: 'center' }}>
        <p>
          请确认是否导出<span style={{ color: 'red' }}>当前入库申请</span>的物资信息！
        </p>
      </div>
    </OneModal>
  );
};

export { ExportModal };
